import { CodeListItem, EditorController } from '@ibiz-template/runtime';
import { ITextBox } from '@ibiz/model-core';

/**
 * @description AI参数控制器
 * @export
 * @class AIParamsController
 * @extends {EditorController<ITextBox>}
 */
export class AIParamsController extends EditorController<ITextBox> {
  /**
   * @description AI参数
   * @type {readonly} 
   * @memberof AIParamsController
   */
  AIParams: readonly CodeListItem[] = [];

  /**
   * @description 初始化
   * @protected
   * @returns {*}  {Promise<void>}
   * @memberof AIParamsController
   */
  protected async onInit(): Promise<void> {
    await super.onInit();
    await this.loadCodeList();
  }

  /**
   * @description 加载代码表
   * @protected
   * @returns {*}  {Promise<void>}
   * @memberof AIParamsController
   */
  protected async loadCodeList(): Promise<void> {
    const { appId } = this.model;
    const { appCodeListId } = this.editorParams;
    if (appCodeListId) {
      const app = await ibiz.hub.getApp(appId);
      this.AIParams = await app.codeList.get(
        appCodeListId,
        this.context,
        this.params,
      );
    }
  }
}
